﻿
Public Class singleThreadTM
    Inherits threadModel

    Protected Overrides Function operImpl(ByVal d As _do(Of ternary), ByVal operationCount As Int64) As ternary
        assert(Not d Is Nothing)
        assert(operationCount > 0)
        Dim startticks As Int64 = 0
        startticks = Now.Ticks()
        Dim rtn As ternary = ternary.unknown
        Dim i As Int64 = 0
        While i < operationCount AndAlso Not overtimelimit(startticks)
            rtn = returnValue(d(), rtn)
            i += 1
        End While

        If i = operationCount Then
            Return rtn
        Else
            Return ternary.false
        End If
    End Function

    Public Shared Sub register(ByVal resolver As resolver)
        resolver.register(Of threadModel)(Function() As threadModel
                                              Return New singleThreadTM()
                                          End Function)
    End Sub

    Public Shared Sub register()
        register(resolver.global)
    End Sub
End Class
